
package edu.uci.ics.crawler4j.url;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;

public class TLDList
{
    private static final String TLD_NAMES_TXT = "tld-names.txt";

    protected static final Logger logger = Logger.getLogger(TLDList.class);

    private static Set<String> tldSet;

    public static boolean contains(String str)
    {
        return tldSet.contains(str);
    }

    static {
        tldSet = new HashSet<String>();
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                TLDList.class.getClassLoader().getResourceAsStream(TLD_NAMES_TXT)));
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                line = line.trim();
                // take care of comments
                if (line.isEmpty() || line.startsWith("//") || line.startsWith("#")) {
                    continue;
                }
                tldSet.add(line);
            }
            reader.close();
        } catch (IOException e) {
            logger.error("I/O error when parsing " + TLD_NAMES_TXT, e);
        }
    }

}
